package com.socialuni.jimei.controller;

import com.socialuni.api.model.RO.user.base.SocialUserRO;
import com.socialuni.api.model.ResultRO;
import com.socialuni.sdk.model.ProviderLoginQO;
import com.socialuni.sdk.model.RO.SocialUserDetailRO;
import com.socialuni.sdk.model.RO.UniLoginRO;
import com.socialuni.sdk.service.SocialUserLoginService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("login")
public class LoginController {
    @Resource
    SocialUserLoginService socialUserLoginService;

    @PostMapping("providerLogin")
    public ResultRO<UniLoginRO<SocialUserDetailRO>> providerLogin(@RequestBody ProviderLoginQO loginQO) {

        UniLoginRO<SocialUserRO> loginRO = socialUserLoginService.providerLogin(loginQO);

        SocialUserRO user = loginRO.getUser();

        SocialUserDetailRO userDetailRO = null;
//        SocialUserDetailRO userDetailRO = SocialUserDetailROFactory.newUserDetailRO(user.getId(), true);

        UniLoginRO<SocialUserDetailRO> uniLoginRO = new UniLoginRO<>(loginRO.getToken(), userDetailRO);

        return new ResultRO<>(uniLoginRO);
    }
}